
#ifndef __T_CONSOLE_H
#define __T_CONSOLE_H

#include "uv.h"

#define console_error(format, args...)                     \
	do                                                     \
	{                                                      \
		printf("\33[31m");                                 \
		printf("Error,%s(),%d::", __FUNCTION__, __LINE__); \
		printf(format, ##args);                            \
		printf("\33[0m");                                  \
	} while (0)

#define console_warn(format, args...)                     \
	do                                                    \
	{                                                     \
		printf("\33[33m");                                \
		printf("Warn,%s(),%d::", __FUNCTION__, __LINE__); \
		printf(format, ##args);                           \
		printf("\33[0m");                                 \
	} while (0)

#define console_msg_declare(module) static int console_msg_level_##module = 3
#define console_msg_level(module, level, format, args...)    \
	do                                                       \
	{                                                        \
		if (level >= console_msg_level_##module)             \
		{                                                    \
			printf("Msg,%s(),%d::", __FUNCTION__, __LINE__); \
			printf(format, ##args);                          \
		}                                                    \
	} while (0)
#define console_msg(module, format, args...) console_msg_level(module, 0, format, ##args)
#define console_level(module, level) console_msg_level_##module = level

#define CONSOLE_UDP_PORT (40001)

#define CONSOLE_CMD_ARGS_NUM (16)
typedef struct _CONSOLE_CMD_PARAM_S
{
	char abyCmd[256];
	int nArgsNum;
	char abyArgs[CONSOLE_CMD_ARGS_NUM][256];
} CONSOLE_CMD_PARAM_S;

typedef int (*CONSOLE_CMD_CB)(CONSOLE_CMD_PARAM_S *, char *);

#define CONSOLE_CMD_MAX (256)
typedef struct _CONSOLE_CMD_NODE_S
{
	char abyCmd[32];
	CONSOLE_CMD_CB cb;
	int nUsed;
} CONSOLE_CMD_NODE_S;

int Console_Loop(uv_work_t *handle);
int Console_CmdAdd(char *pCmd, CONSOLE_CMD_CB cb);
int Console_CmdDel(char *pCmd);
int Console_Init(void);
int Console_DeInit(void);

#endif